
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.structure_prediction.volume_predictor &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.structure_prediction.volume_predictor</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.structure_prediction.volume_predictor</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Predict volumes of crystal structures.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.bond_valence</span> <span class="kn">import</span> <span class="n">BVAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.structure_matcher</span> <span class="kn">import</span> <span class="n">StructureMatcher</span>
<span class="kn">from</span> <span class="nn">pymatgen.core</span> <span class="kn">import</span> <span class="n">Structure</span>

<span class="n">MODULE_DIR</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
<span class="n">bond_params</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">MODULE_DIR</span><span class="p">,</span> <span class="s1">&#39;DLS_bond_params.yaml&#39;</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">_is_ox</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
    <span class="n">comp</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">composition</span>
    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">comp</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">k</span><span class="o">.</span><span class="n">oxi_state</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
    <span class="k">return</span> <span class="kc">True</span>


<div class="viewcode-block" id="RLSVolumePredictor"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.RLSVolumePredictor">[docs]</a><span class="k">class</span> <span class="nc">RLSVolumePredictor</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Reference lattice scaling (RLS) scheme that predicts the volume of a</span>
<span class="sd">    structure based on a known crystal structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">check_isostructural</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">radii_type</span><span class="o">=</span><span class="s2">&quot;ionic-atomic&quot;</span><span class="p">,</span>
                 <span class="n">use_bv</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            check_isostructural: Whether to test that the two structures are</span>
<span class="sd">                isostructural. This algo works best for isostructural compounds.</span>
<span class="sd">                Defaults to True.</span>
<span class="sd">            radii_type (str): Types of radii to use. You can specify &quot;ionic&quot;</span>
<span class="sd">                (only uses ionic radii), &quot;atomic&quot; (only uses atomic radii) or</span>
<span class="sd">                &quot;ionic-atomic&quot; (uses either ionic or atomic radii, with a</span>
<span class="sd">                preference for ionic where possible).</span>
<span class="sd">            use_bv (bool): Whether to use BVAnalyzer to determine oxidation</span>
<span class="sd">                states if not present.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_isostructural</span> <span class="o">=</span> <span class="n">check_isostructural</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">radii_type</span> <span class="o">=</span> <span class="n">radii_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">use_bv</span> <span class="o">=</span> <span class="n">use_bv</span>

<div class="viewcode-block" id="RLSVolumePredictor.predict"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.RLSVolumePredictor.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">ref_structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Given a structure, returns the predicted volume.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): structure w/unknown volume</span>
<span class="sd">            ref_structure (Structure): A reference structure with a similar</span>
<span class="sd">                structure but different species.</span>
<span class="sd">        Returns:</span>
<span class="sd">            a float value of the predicted volume</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_isostructural</span><span class="p">:</span>
            <span class="n">m</span> <span class="o">=</span> <span class="n">StructureMatcher</span><span class="p">()</span>
            <span class="n">mapping</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">get_best_electronegativity_anonymous_mapping</span><span class="p">(</span>
                <span class="n">structure</span><span class="p">,</span> <span class="n">ref_structure</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">mapping</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Input structures do not match!&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s2">&quot;ionic&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">radii_type</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># Use BV analyzer to determine oxidation states only if the</span>
                <span class="c1"># oxidation states are not already specified in the structure</span>
                <span class="c1"># and use_bv is true.</span>
                <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">_is_ox</span><span class="p">(</span><span class="n">structure</span><span class="p">))</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bv</span><span class="p">:</span>
                    <span class="n">a</span> <span class="o">=</span> <span class="n">BVAnalyzer</span><span class="p">()</span>
                    <span class="n">structure</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">get_oxi_state_decorated_structure</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
                <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">_is_ox</span><span class="p">(</span><span class="n">ref_structure</span><span class="p">))</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">use_bv</span><span class="p">:</span>
                    <span class="n">a</span> <span class="o">=</span> <span class="n">BVAnalyzer</span><span class="p">()</span>
                    <span class="n">ref_structure</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">get_oxi_state_decorated_structure</span><span class="p">(</span>
                        <span class="n">ref_structure</span><span class="p">)</span>

                <span class="n">comp</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">composition</span>
                <span class="n">ref_comp</span> <span class="o">=</span> <span class="n">ref_structure</span><span class="o">.</span><span class="n">composition</span>

                <span class="c1"># Check if all the associated ionic radii are available.</span>
                <span class="k">if</span> <span class="nb">any</span><span class="p">([</span><span class="n">k</span><span class="o">.</span><span class="n">ionic_radius</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">comp</span><span class="o">.</span><span class="n">keys</span><span class="p">())])</span> <span class="ow">or</span> \
                        <span class="nb">any</span><span class="p">([</span><span class="n">k</span><span class="o">.</span><span class="n">ionic_radius</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span>
                             <span class="nb">list</span><span class="p">(</span><span class="n">ref_comp</span><span class="o">.</span><span class="n">keys</span><span class="p">())]):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Not all the ionic radii are available!&quot;</span><span class="p">)</span>

                <span class="n">numerator</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">denominator</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="c1"># Here, the 1/3 factor on the composition accounts for atomic</span>
                <span class="c1"># packing. We want the number per unit length.</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">comp</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">numerator</span> <span class="o">+=</span> <span class="n">k</span><span class="o">.</span><span class="n">ionic_radius</span> <span class="o">*</span> <span class="n">v</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ref_comp</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">denominator</span> <span class="o">+=</span> <span class="n">k</span><span class="o">.</span><span class="n">ionic_radius</span> <span class="o">*</span> <span class="n">v</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>

                <span class="k">return</span> <span class="n">ref_structure</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="p">(</span><span class="n">numerator</span> <span class="o">/</span> <span class="n">denominator</span><span class="p">)</span> <span class="o">**</span> <span class="mi">3</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Exception occured. Will attempt atomic radii.&quot;</span><span class="p">)</span>
                <span class="c1"># If error occurs during use of ionic radii scheme, pass</span>
                <span class="c1"># and see if we can resolve it using atomic radii.</span>
                <span class="k">pass</span>

        <span class="k">if</span> <span class="s2">&quot;atomic&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">radii_type</span><span class="p">:</span>
            <span class="n">comp</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">composition</span>
            <span class="n">ref_comp</span> <span class="o">=</span> <span class="n">ref_structure</span><span class="o">.</span><span class="n">composition</span>
            <span class="c1"># Here, the 1/3 factor on the composition accounts for atomic</span>
            <span class="c1"># packing. We want the number per unit length.</span>
            <span class="n">numerator</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">denominator</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">comp</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">numerator</span> <span class="o">+=</span> <span class="n">k</span><span class="o">.</span><span class="n">atomic_radius</span> <span class="o">*</span> <span class="n">v</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ref_comp</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">denominator</span> <span class="o">+=</span> <span class="n">k</span><span class="o">.</span><span class="n">atomic_radius</span> <span class="o">*</span> <span class="n">v</span> <span class="o">**</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">ref_structure</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="p">(</span><span class="n">numerator</span> <span class="o">/</span> <span class="n">denominator</span><span class="p">)</span> <span class="o">**</span> <span class="mi">3</span>

        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Cannot find volume scaling based on radii choices &quot;</span>
                         <span class="s2">&quot;specified!&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="RLSVolumePredictor.get_predicted_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.RLSVolumePredictor.get_predicted_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_predicted_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">ref_structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Given a structure, returns back the structure scaled to predicted</span>
<span class="sd">        volume.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): structure w/unknown volume</span>
<span class="sd">            ref_structure (Structure): A reference structure with a similar</span>
<span class="sd">                structure but different species.</span>
<span class="sd">        Returns:</span>
<span class="sd">            a Structure object with predicted volume</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_structure</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">new_structure</span><span class="o">.</span><span class="n">scale_lattice</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">ref_structure</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">new_structure</span></div></div>


<div class="viewcode-block" id="DLSVolumePredictor"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.DLSVolumePredictor">[docs]</a><span class="k">class</span> <span class="nc">DLSVolumePredictor</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Data-mined lattice scaling (DLS) scheme that relies on data-mined bond</span>
<span class="sd">    lengths to predict the crystal volume of a given structure.</span>

<span class="sd">    As of 2/12/19, we suggest this method be used in conjunction with</span>
<span class="sd">    min_scaling and max_scaling to prevent instances of very large, unphysical</span>
<span class="sd">    predicted volumes found in a small subset of structures.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cutoff</span><span class="o">=</span><span class="mf">4.0</span><span class="p">,</span> <span class="n">min_scaling</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">max_scaling</span><span class="o">=</span><span class="mf">1.5</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            cutoff (float): cutoff radius added to site radius for finding</span>
<span class="sd">                site pairs. Necessary to increase only if your initial</span>
<span class="sd">                structure guess is extremely bad (atoms way too far apart). In</span>
<span class="sd">                all other instances, increasing cutoff gives same answer</span>
<span class="sd">                but takes more time.</span>
<span class="sd">            min_scaling (float): if not None, this will ensure that the new</span>
<span class="sd">                volume is at least this fraction of the original (preventing</span>
<span class="sd">                too-small volumes)</span>
<span class="sd">            max_scaling (float): if not None, this will ensure that the new</span>
<span class="sd">                volume is at most this fraction of the original (preventing</span>
<span class="sd">                too-large volumes)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cutoff</span> <span class="o">=</span> <span class="n">cutoff</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_scaling</span> <span class="o">=</span> <span class="n">min_scaling</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_scaling</span> <span class="o">=</span> <span class="n">max_scaling</span>

<div class="viewcode-block" id="DLSVolumePredictor.predict"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.DLSVolumePredictor.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">icsd_vol</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Given a structure, returns the predicted volume.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure) : a crystal structure with an unknown volume.</span>
<span class="sd">            icsd_vol (bool) : True if the input structure&#39;s volume comes from</span>
<span class="sd">                ICSD.</span>

<span class="sd">        Returns:</span>
<span class="sd">            a float value of the predicted volume.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Get standard deviation of electronnegativity in the structure.</span>
        <span class="n">std_x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">([</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">X</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">])</span>
        <span class="c1"># Sites that have atomic radii</span>
        <span class="n">sub_sites</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># Record the &quot;DLS estimated radius&quot; from bond_params.</span>
        <span class="n">bp_dict</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">sp</span><span class="o">.</span><span class="n">atomic_radius</span><span class="p">:</span>
                <span class="n">sub_sites</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">site</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span>
                                  <span class="k">if</span> <span class="n">site</span><span class="o">.</span><span class="n">specie</span> <span class="o">==</span> <span class="n">sp</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;VolumePredictor: no atomic radius data for &quot;</span>
                              <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">sp</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">sp</span><span class="o">.</span><span class="n">symbol</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">bond_params</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;VolumePredictor: bond parameters not found, &quot;</span>
                              <span class="s2">&quot;used atomic radii for </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">sp</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">r</span><span class="p">,</span> <span class="n">k</span> <span class="o">=</span> <span class="n">bond_params</span><span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">][</span><span class="s2">&quot;r&quot;</span><span class="p">],</span> <span class="n">bond_params</span><span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">][</span><span class="s2">&quot;k&quot;</span><span class="p">]</span>
                <span class="n">bp_dict</span><span class="p">[</span><span class="n">sp</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="o">+</span> <span class="nb">float</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="o">*</span> <span class="n">std_x</span>

        <span class="c1"># Structure object that include only sites with known atomic radii.</span>
        <span class="n">reduced_structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_sites</span><span class="p">(</span><span class="n">sub_sites</span><span class="p">)</span>
        <span class="n">smallest_ratio</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">for</span> <span class="n">site1</span> <span class="ow">in</span> <span class="n">reduced_structure</span><span class="p">:</span>
            <span class="n">sp1</span> <span class="o">=</span> <span class="n">site1</span><span class="o">.</span><span class="n">specie</span>
            <span class="n">neighbors</span> <span class="o">=</span> <span class="n">reduced_structure</span><span class="o">.</span><span class="n">get_neighbors</span><span class="p">(</span><span class="n">site1</span><span class="p">,</span>
                                                        <span class="n">sp1</span><span class="o">.</span><span class="n">atomic_radius</span> <span class="o">+</span>
                                                        <span class="bp">self</span><span class="o">.</span><span class="n">cutoff</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">nn</span> <span class="ow">in</span> <span class="n">neighbors</span><span class="p">:</span>
                <span class="n">sp2</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">specie</span>

                <span class="k">if</span> <span class="n">sp1</span> <span class="ow">in</span> <span class="n">bp_dict</span> <span class="ow">and</span> <span class="n">sp2</span> <span class="ow">in</span> <span class="n">bp_dict</span><span class="p">:</span>
                    <span class="n">expected_dist</span> <span class="o">=</span> <span class="n">bp_dict</span><span class="p">[</span><span class="n">sp1</span><span class="p">]</span> <span class="o">+</span> <span class="n">bp_dict</span><span class="p">[</span><span class="n">sp2</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">expected_dist</span> <span class="o">=</span> <span class="n">sp1</span><span class="o">.</span><span class="n">atomic_radius</span> <span class="o">+</span> <span class="n">sp2</span><span class="o">.</span><span class="n">atomic_radius</span>

                <span class="k">if</span> <span class="ow">not</span> <span class="n">smallest_ratio</span> <span class="ow">or</span> <span class="n">nn</span><span class="o">.</span><span class="n">nn_distance</span> <span class="o">/</span> <span class="n">expected_dist</span> <span class="o">&lt;</span> <span class="n">smallest_ratio</span><span class="p">:</span>
                    <span class="n">smallest_ratio</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">nn_distance</span> <span class="o">/</span> <span class="n">expected_dist</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">smallest_ratio</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Could not find any bonds within the given cutoff &quot;</span>
                             <span class="s2">&quot;in this structure.&quot;</span><span class="p">)</span>

        <span class="n">volume_factor</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">/</span> <span class="n">smallest_ratio</span><span class="p">)</span> <span class="o">**</span> <span class="mi">3</span>

        <span class="c1"># icsd volume fudge factor</span>
        <span class="k">if</span> <span class="n">icsd_vol</span><span class="p">:</span>
            <span class="n">volume_factor</span> <span class="o">*=</span> <span class="mf">1.05</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_scaling</span><span class="p">:</span>
            <span class="n">volume_factor</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_scaling</span><span class="p">,</span> <span class="n">volume_factor</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_scaling</span><span class="p">:</span>
            <span class="n">volume_factor</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_scaling</span><span class="p">,</span> <span class="n">volume_factor</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">structure</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="n">volume_factor</span></div>

<div class="viewcode-block" id="DLSVolumePredictor.get_predicted_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.structure_prediction.volume_predictor.html#pymatgen.analysis.structure_prediction.volume_predictor.DLSVolumePredictor.get_predicted_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_predicted_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">icsd_vol</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Given a structure, returns back the structure scaled to predicted</span>
<span class="sd">        volume.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): structure w/unknown volume</span>

<span class="sd">        Returns:</span>
<span class="sd">            a Structure object with predicted volume</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_structure</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">new_structure</span><span class="o">.</span><span class="n">scale_lattice</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">icsd_vol</span><span class="o">=</span><span class="n">icsd_vol</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">new_structure</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.structure_prediction.volume_predictor</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>